package com.ruoyi.edge.gateway.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.edge.gateway.domain.Equipment;
import com.ruoyi.edge.gateway.service.EquipmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 边缘计算设备管理
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/equipment")
public class EquipmentController extends BaseController {

    private final EquipmentService equipmentService;

    /**
     * 获取列表
     */
    @SaCheckPermission("edge:equipment:listPage")
    @GetMapping("/listPage")
    public TableDataInfo<Equipment> listPage(Equipment equipment, PageQuery pageQuery) {
        return equipmentService.listPage(equipment, pageQuery);
    }

    /**
     * 获取下拉参数
     */
    @SaCheckPermission("edge:equipment:list")
    @GetMapping("/list")
    public R<List<Equipment>> list(Equipment equipment) {
        return equipmentService.list(equipment);
    }


    @SaCheckPermission("edge:equipment:get")
    @GetMapping("/get")
    public R<Equipment> get(String id) {
        return equipmentService.get(id);
    }

    /**
     * 新增
     */
    @SaCheckPermission("edge:equipment:add")
    @PostMapping("add")
    public R<String> add(@RequestBody Equipment equipment) {
        return equipmentService.add(equipment);
    }

    /**
     * 编辑
     */
    @SaCheckPermission("edge:equipment:edit")
    @PutMapping("edit")
    public R<String> edit(@RequestBody Equipment equipment) {
        return equipmentService.edit(equipment);
    }

    /**
     * 删除
     */
    @SaCheckPermission("edge:equipment:remove")
    @DeleteMapping("remove")
    public R<String> remove(String id) {
        return equipmentService.remove(id);
    }

    /**
     * 修改状态
     */
    @SaCheckPermission("edge:equipment:editStatus")
    @PutMapping("editStatus")
    public R<String> editStatus(@RequestParam("id") String id,
                        @RequestParam("status") Integer status) {
        return equipmentService.editStatus(id, status);
    }

}
